package com.xiaoh.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 文件拷贝
 *
 * @author xiaoH
 * @date 2020/4/29
 * @description
 */
public class NIOFileChannel04 {

    public static void main(String[] args) throws IOException {

        FileInputStream fileInputStream = new FileInputStream("/Users/xiaoh/Desktop/09-OCR//aa.png");
        //通过fileInputStream获取对应的FileChannel -> FileChannelImpl
        FileChannel sourceChannel = fileInputStream.getChannel();

        FileOutputStream fileOutputStream = new FileOutputStream("/Users/xiaoh/Desktop/09-OCR/aa2.png");
        FileChannel destChannel = fileOutputStream.getChannel();

        destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());

        //关闭相关的流
        sourceChannel.close();
        destChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
